<template>
  <div>
    <x-button type="primary" @click.native="callAndroid">调用Android的方法,然后Android调用js方法</x-button>

    <x-button type="primary" style="margin-top: 100px" @click.native="callIos">调用IOS的方法,然后Android调用js方法</x-button>


    <div v-show="showMsg">{{Msg}}</div>
  </div>



</template>

<script>
  import XButton from "vux/src/components/x-button/index";
  export default {
    name: "Jstest",
    data() {
      return {
        showMsg:true,
        Msg:'原始数据'
      }
    },
    methods: {
      callAndroid() {
         window.androidHandler.calledByJs('vue传递参数给Android')
      },
      calledByAndroid(res) {
        alert(res)
        return "js方法返回值"
      },

      calledByIos(res){
        alert(res)
        this.Msg = res
      },
      callIos(){
//        调用ios方法
        window.webkit.messageHandlers.currentTitle.postMessage("home");

      }
    },
    components: {XButton},
    mounted() {
      //需要挂在到window上 否则移动端无法调用成功
      window.calledByAndroid = this.calledByAndroid

      window.calledByIos = this.calledByIos
    },

  }
</script>

<style scoped>

</style>
